bitkeeper revision 1.1159.79.1 (414b5fab__RjPaRIcKFGQmiG7K6ggA)
authorkaf24@freefall.cl.cam.ac.uk <kaf24@freefall.cl.cam.ac.uk>
Fri, 17 Sep 2004 22:05:31 +0000 (22:05 +0000)
committerkaf24@freefall.cl.cam.ac.uk <kaf24@freefall.cl.cam.ac.uk>
Fri, 17 Sep 2004 22:05:31 +0000 (22:05 +0000)
SrvDaemon.py, xend:
  Xend daemonization fixes from Charles Coffing.

tools/examples/init.d/xend
tools/misc/xend
tools/python/xen/xend/server/SrvDaemon.py

index df12768140e9680220579a72258a1acf7baf7d26..7037848166c4d35bc24bac96fbd8bc8558126530 100755 (executable)
 case "$1" in
   start)
        xend start
-       exit $?
        ;;
   stop)
        xend stop
-       exit $?
        ;;
   status)
+       xend status
        ;;
   restart|reload)
+       xend restart
        ;;
   *)
        # do not advertise unreasonable commands that there is no reason
@@ -27,5 +27,5 @@ case "$1" in
        exit 1
 esac
 
-exit 0
+exit $?
 
index d04e5c77df9ef9eba3880d21c5adcef58f724e77..57138c1ebf649498fab77a2c0c503a0efc573af7 100644 (file)
@@ -8,11 +8,12 @@
    Provides console server and HTTP management api.
 
    Run:
-
    xend start
 
-   The daemon is stopped with:
+   Restart:
+   xend restart
 
+   The daemon is stopped with:
    xend stop
 
    The daemon should reconnect to device control interfaces
@@ -107,6 +108,8 @@ def main():
         return daemon.stop()
     elif sys.argv[1] == 'restart':
         return daemon.stop() or daemon.start()
+    elif sys.argv[1] == 'status':
+        return daemon.status()
     else:
         print 'not an option:', sys.argv[1]
     return 1
index 20569c74b4c9ac09edd4e68d775c8642853cdfd5..bdd4db83c081afdbc8a3ea481b40f08c9b317834 100644 (file)
@@ -42,7 +42,7 @@ import console
 import domain
 from params import *
 
-DEBUG = 1
+DEBUG = 0
 
 class NotifierProtocol(protocol.Protocol):
     """Asynchronous handler for i/o on the notifier (event channel).
@@ -419,6 +419,18 @@ class Daemon:
         self.cleanup_xend(kill=kill)
         self.cleanup_xfrd(kill=kill)
             
+    def status(self):
+        """Returns the status of the xend and xfrd daemons.
+        The return value is defined by the LSB:
+        0  Running
+        3  Not running
+        """
+        if (self.cleanup_process(XEND_PID_FILE, "xend", False) == 0 or
+            self.cleanup_process(XFRD_PID_FILE, "xfrd", False) == 0):
+            return 3
+        else:
+            return 0
+
     def install_child_reaper(self):
         #signal.signal(signal.SIGCHLD, self.onSIGCHLD)
         # Ensure that zombie children are automatically reaped.
@@ -451,22 +463,36 @@ class Daemon:
             pass
         else:
             # Child
-            self.set_user()
             os.execl("/usr/sbin/xfrd", "xfrd")
             
     def start(self, trace=0):
+        """Attempts to start the daemons.
+        The return value is defined by the LSB:
+        0  Success
+        4  Insufficient privileges
+        """
         xend_pid = self.cleanup_xend()
         xfrd_pid = self.cleanup_xfrd()
-        if xfrd_pid == 0:
-            self.start_xfrd()
-        if xend_pid > 0:
-            return 1
 
         # Detach from TTY.
         if not DEBUG:
             os.setsid()
+            sys.stdin.close();
+            sys.stdout.close();
+            sys.stderr.close();
+            os.close(0);
+            os.close(1);
+            os.close(2);
         if self.set_user():
-            return 1
+            return 4
+        os.chdir("/")
+
+        if xfrd_pid == 0:
+            self.start_xfrd()
+        if xend_pid > 0:
+            # Trying to run an already-running service is a success.
+            return 0
+
         self.install_child_reaper()
 
         if self.fork_pid(XEND_PID_FILE):